#!/usr/bin/python

'''
    Here is the exercise for operator of python.
    first   --  arithmetic operator
    second  --  comparator operator
    third   --  assignment operator
    fourth  --  logic operator
    fifth   --  bit operator
    sixth   --  member operator
    seventh --  identity operator

'''

'''first   --  arithmetic operator
    +
    -
    *
    /
    //
    **
    %
'''

a = 5
b = 2

print('a + b = ', a + b)
print('a - b = ', a - b)
print('a * b = ', a * b)
print('a / b = ', a / b)
print('a // b = ', a // b)
print('a ** b = ', a ** b)
print('a % b = ', a % b)

print('=============================================')

'''
    second  --  comparator operator
    
    ==
    !=
    >
    <
    <=
    >=
'''
a = 10
b = 19
c = 10

print('a == b is ', a == b)
print('a != b is ', a != b)
print('a > b is ', a > b)
print('a < b is ', a < b)
print('a <= b is ', a <= b, ', a <= c is ', a <= c)
print('a >= b is ', a >= b, ', a >= c is ', a >= c)
print('=============================================')

'''
    third   --  assignment operator

    =
    +=
    -=
    *=
    /=
    %=
    **=
    //=
'''

a = 5
b = 2
c = 0

c = a + b
print(c)

c += a + b

print(c)

c -= a + b
print(c)

c *= a
print(c)

c /= b
print(c)

c %= b
print(c)

c **= b
print(c)

c //= b
print(c)
print('=============================================')

'''
    fourth  --  logic operator
    
    and
    or
    not
'''
a = 10
b = 120

if a and b:
    print('a and b is true')
else:
    print('a or b is false')

if a or b:
    print('a or b is true')
else:
    print('a and b is both false')

if not a:
    print('a is false')
else:
    print('a is true')
print('=============================================')

'''
    fifth   --  bit operator

    &
    |
    ^
    ~
'''

a = 60  # 00111100'
b = 13  # 00001101

print(a & b)

print(a | b)

print(a ^ b)

print(~a)  # -a-1

print(a << 2)

print(a >> 2)
print('=============================================')

'''

    sixth   --  member operator

    in
    not in
    
'''
a = 2
b = 3
list = [1, 4, 5, 2]

if a in list:
    print('a in list')
else:
    print('a not in list')

if b not in list:
    print('b not in list')
else:
    print('b in list')
print('=============================================')

'''
    seventh --  identity operator

    is 
    is not
'''

a = 10
b = 10
c = 20

if a is b:
    print("a is b")
else:
    print("a is not b")

if a is not b:
    print('a is not b')
else:
    print('a is b')

if a is c:
    print('a is c')
else:
    print('a is not c')

listA = [1, 2, 3]

listB = listA

print(listB is listA)
print(listB == listA)
print(id(listA))
print(id(listB))

listB = listA[:]
print(listB is listA)
print(listB == listA)
print('=============================================')

a = 0b11001100
b = 0b00001101  # 二进制 0b开头
c = 0o10  # 8 八进制 0o开头
d = 0x11  # 17 十六进制 0x开头
print(bin(a & b))  # print as binary

print(oct(a & b))

print(hex(a & b))

a = 5
b = a
print(id(a))
print(id(b))
a += 1
print(id(a))
print(id(b))
